package com.ruoyi.xds.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.xds.domain.XdsAttribute;
import com.ruoyi.xds.service.IXdsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺属性Controller
 *
 * @author ruoyi
 * @date 2025-09-01
 */
@RestController
@RequestMapping("/system/attribute")
public class XdsAttributeController extends BaseController {
    @Autowired
    private IXdsAttributeService xdsAttributeService;

    /**
     * 查询店铺属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(XdsAttribute xdsAttribute) {
        startPage();
        List<XdsAttribute> list = xdsAttributeService.selectXdsAttributeList(xdsAttribute);
        return getDataTable(list);
    }

    /**
     * 导出店铺属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:export')")
    @Log(title = "店铺属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XdsAttribute xdsAttribute) {
        List<XdsAttribute> list = xdsAttributeService.selectXdsAttributeList(xdsAttribute);
        ExcelUtil<XdsAttribute> util = new ExcelUtil<XdsAttribute>(XdsAttribute.class);
        util.exportExcel(response, list, "店铺属性数据");
    }

    /**
     * 获取店铺属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xdsAttributeService.selectXdsAttributeById(id));
    }

    /**
     * 新增店铺属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:add')")
    @Log(title = "店铺属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XdsAttribute xdsAttribute) {
        xdsAttribute.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(xdsAttributeService.insertXdsAttribute(xdsAttribute));
    }

    /**
     * 修改店铺属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:edit')")
    @Log(title = "店铺属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XdsAttribute xdsAttribute) {
        xdsAttribute.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(xdsAttributeService.updateXdsAttribute(xdsAttribute));
    }

    /**
     * 删除店铺属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:remove')")
    @Log(title = "店铺属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xdsAttributeService.deleteXdsAttributeByIds(ids));
    }
}
